package com.vlin.device.value.converter;

public abstract class AbstractConditionHandler implements ConditionHandler {
	
	
	private Converter converter;



	@Override
	public boolean isOutOfRange(String value, Condition condition) {
		if(!supportCondition(condition)) {
			return true;
		}
		
		Class<?> clazz = condition.convertClass();
		if(getConverter().canConvert(value, clazz)) {
			Object result = getConverter().convert(value, clazz);
			if(!outOfRange(result, condition)) {
				return false;
			}
		}
		return true;
	}
	
	abstract public boolean outOfRange(Object value, Condition condition);

	@Override
	public Object getResult(String value, Condition condition) {
		Class<?> clazz = condition.convertClass();
		return getConverter().convert(value, clazz);
	}

	@Override
	public void setConverter(Converter converter) {
		this.converter = converter;
		
	}

	@Override
	public Converter getConverter() {
		
		return this.converter;
	}


}
